from tkinter import *
class ChangeLabelDemo:
    def __init__(self):
        window = Tk()
        window.title ("改变文本")

        frame1 = Frame(window)
        frame1.pack()

        self.lb1 = Label(frame1,text='这个程序很有趣哦。')
        self.lb1.pack()


        frame2 = Frame(window)
        frame2.pack()

        label = Label(frame2,text='输入：')
        self.msg = StringVar()

        entry = Entry(frame2,textvariable=self.msg)
        btChangeText = Button(frame2,text='提交',command=self.processButton)
        self.v1 = StringVar()
        rbRed = Radiobutton(frame2,text='红色',bg='red',variable=self.v1,value='R',command=self.processRadionbutton)
        rbYellow = Radiobutton(frame2,text='黄色',bg='yellow',variable=self.v1,value='Y',command=self.processRadionbutton)
        

        label.grid(row=1,column = 1)
        entry.grid(row=1,column = 2)
        btChangeText.grid(row=1,column = 3)
        rbRed.grid(row=1,column = 4)
        rbYellow.grid(row=1,column = 5)

        window.mainloop()

    def processRadionbutton(self):
        if self.v1.get() == 'R':
            self.lb1['fg'] = 'red'
        else:
            self.lb1['fg'] = 'yellow'

    def processButton(self):
        self.lb1['text'] = self.msg.get()

ChangeLabelDemo()
